<?php
session_start();
//判断是否已经登录
if(isset($_SESSION['slast_key'])) 
{
	header("Location:".SiteUrl."/index.php");
	exit;	
}
include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );

$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );


if (isset($_REQUEST['code'])) {
	$keys = array();
	$keys['code'] = $_REQUEST['code'];
	$keys['redirect_uri'] = WB_CALLBACK_URL;
	try {
		$token = $o->getAccessToken( 'code', $keys ) ;
	} catch (OAuthException $e) {
	}
}


if ($token) {
	$_SESSION['token'] = $token;
	setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
	//转到注册登录页面
	
	$oo=new SaeTClientV2(WB_AKEY,WB_SKEY,$token['access_token'],$o->client_secret);
	try {
		$uidinfo = $oo->show_user_by_id( $token['uid'] ) ;
	} catch (OAuthException $e) {
	}
	

	print_r($uidinfo);

	print_r('<br/><br/>');
	print_r($token);
	
	print_r('<br/><br/>');
	print_r($o->access_token);
	
	print_r('<br/><br/>');
	
	print_r($o);exit;
	
	
	
@header('location: /index.php');
	exit;
} else { echo "授权失败。"; }
